package root.electronclass.electronclass.school

import android.os.Bundle
import android.view.View
import root.electronclass.electronclass.common.base.BasicAdapter
import root.electronclass.electronclass.common.base.ViewBindingFragment
import root.electronclass.electronclass.mvp.entity.IdeaBox
import root.electronclass.electronclass.R
import root.electronclass.electronclass.databinding.FragmentSchoolDynamicBinding
import root.electronclass.electronclass.databinding.FragmentSchoolStudyItemBinding
import root.electronclass.electronclass.databinding.FragmentSchoolStudyItemItemBinding
import root.electronclass.electronclass.ext.doOnSearch
import root.electronclass.electronclass.ext.tabs
import root.electronclass.electronclass.ext.toDateYyyyMMdd
import root.electronclass.electronclass.grade.model.ClassDateGroup


class SchoolDynamicFragment : ViewBindingFragment<FragmentSchoolDynamicBinding>() {
    private var pageNum = 1
    private var total = 0
    private var searchContent: String? = null
    private var dataType = 1


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val tabs = resources.getStringArray(R.array.class_tabs)
        binding.tabLayout.tabs(tabs) { tab ->
            val text = binding.search.text.toString()
        }

        binding.recycler.adapter = adapter
        binding.search.doOnSearch {
            false
        }

    }


    private val adapter = BasicAdapter<ClassDateGroup<IdeaBox>, FragmentSchoolStudyItemBinding> { holder, item ->
        holder.binding.itemTitle.text = item.time.toDateYyyyMMdd()
        val childAdapter = BasicAdapter<IdeaBox, FragmentSchoolStudyItemItemBinding> { holder1, childItem ->

        }
        holder.binding.itemRecycler.adapter = childAdapter
        childAdapter.refresh(item.data)
    }

    private fun getData() {
        showWaitingMessage()
        val box = IdeaBox()
        box.dateType = dataType
        box.pageNum = pageNum
        box.remark = searchContent

//        RestManager.getInstance().initRest().ideaBox(box)
//            .enqueue(object : CallbackNext<BaseResponse<List<IdeaBox>>>(mDialogViewModel) {
//                override fun onSuccessful(
//                    call: Call<BaseResponse<List<IdeaBox>>>,
//                    response: BaseResponse<List<IdeaBox>>
//                ) {
//                    if (response.isSuccess) {
//                        total = response.total
//                        val list = response.rows.groupBy { it.createTime }
//                        val mapList = mutableListOf<GroupData<IdeaBox>>()
//                        for (i in list){
//                            mapList.add(GroupData(i.key,i.value))
//                        }
//                        val  sortedMap = mapList.sortedBy { it.createTime }
////                        adapter.refresh(sortedMap)
//                    }
//                    dismissProgress()
//                }
//
//                override fun onError(
//                    call: Call<BaseResponse<List<IdeaBox>>>?,
//                    response: BaseResponse<List<IdeaBox>>?
//                ) {
//                    dismissProgress()
//                }
//            })
    }

}